package sys_job

import (
	"database/sql"
	"github.com/gogf/gf/database/gdb"
)

// Entity is the golang structure for table sys_job.
type Entity struct {
	JobId          int64  `orm:"job_id,primary"    json:"job_id"`          // 任务ID
	JobName        string `orm:"job_name,primary"  json:"job_name"`        // 任务名称
	JobParams      string `orm:"job_params"        json:"job_params"`      // 参数
	JobGroup       string `orm:"job_group,primary" json:"job_group"`       // 任务组名
	InvokeTarget   string `orm:"invoke_target"     json:"invoke_target"`   // 调用目标字符串
	CronExpression string `orm:"cron_expression"   json:"cron_expression"` // cron执行表达式
	MisfirePolicy  int    `orm:"misfire_policy"    json:"misfire_policy"`  // 计划执行策略（1多次执行 2执行一次）
	Concurrent     int    `orm:"concurrent"        json:"concurrent"`      // 是否并发执行（0允许 1禁止）
	Status         int    `orm:"status"            json:"status"`          // 状态（0正常 1暂停）
	CreateBy       uint64 `orm:"create_by"         json:"create_by"`       // 创建者
	CreateTime     uint64 `orm:"create_time"       json:"create_time"`     // 创建时间
	UpdateBy       uint64 `orm:"update_by"         json:"update_by"`       // 更新者
	UpdateTime     uint64 `orm:"update_time"       json:"update_time"`     // 更新时间
	Remark         string `orm:"remark"            json:"remark"`          // 备注信息
}

// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
// the data and where attributes for empty values.
func (r *Entity) OmitEmpty() *arModel {
	return Model.Data(r).OmitEmpty()
}

// Inserts does "INSERT...INTO..." statement for inserting current object into table.
func (r *Entity) Insert() (result sql.Result, err error) {
	return Model.Data(r).Insert()
}

// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
	return Model.Data(r).InsertIgnore()
}

// Replace does "REPLACE...INTO..." statement for inserting current object into table.
// If there's already another same record in the table (it checks using primary key or unique index),
// it deletes it and insert this one.
func (r *Entity) Replace() (result sql.Result, err error) {
	return Model.Data(r).Replace()
}

// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *Entity) Save() (result sql.Result, err error) {
	return Model.Data(r).Save()
}

// Update does "UPDATE...WHERE..." statement for updating current object from table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *Entity) Update() (result sql.Result, err error) {
	return Model.Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
}

// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
func (r *Entity) Delete() (result sql.Result, err error) {
	return Model.Where(gdb.GetWhereConditionOfStruct(r)).Delete()
}
